/**
 * <p>图形的Panel，包含图形控件和保存图片按钮</p>
 * xtype = cceafchartpanel
 
 * @module Ext-ux-cceaf-control
 * @class cceaf.control.ChartPanel
 * @extends Ext.panel.Panel
 * @since 1.0
 */
Ext.define('cceaf.control.ChartPanel',{
	extend: 'Ext.panel.Panel', 
    alias: 'widget.cceafchartpanel',
    
    requires: [
        'Ext.button.Button'
    ],

	constructor: function(config){
		config = config || {};
		       
		cceaf.control.ChartPanel.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * 图形控件
	 *
     * @property chart 
     * @type cceaf.control.Chart
     * @default null
     */
	chart: null,
	
	initComponent : function(){
		var config = this;
		
		var chart = config.chart;
		Ext.applyIf(this, {
			frame: true,
	        border: false,
	        layout: 'fit',
	        tbar:[
	        	{
		            xtype: 'button',
	        		text: '保存为图片',
		            handler: function(btn) {
		                Ext.MessageBox.confirm('确认保存', '你确定要保存图标为图片吗?', function(choice){
		                    if(choice == 'yes'){
		                    	var chart = btn.up('panel').down('cceafchart');
		                        chart.save({
		                            type: 'image/png',
		                            url: '/' + cceaf.Global.WEB_APP_NAME + '/svg!convert.action'
		                        });
		                    }
		                });
		            }
		        }
	        ],
	        
	        items: [ chart ]
            
		});
		
		cceaf.control.ChartPanel.superclass.initComponent.call(this);
    },

    initEvents: function() {
    	cceaf.control.ChartPanel.superclass.initEvents.call(this);
    }
});